/*
    YmsgIRC - Program enabling YMSG chat clients to use IRC
    Copyright (C) 2011 Crash Daemonicus ( crashenator -at- gmail.com )

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common.h"
#include "network.h"
#include "YMSG_constants.h"
#include "YMSG_head.h"
#include "YMSG_field.h"
#include "YMSG_list.h"
#include "YMSG_packet.h"
#include "YMSG_fieldparser.h"



class YMSG : public NwNetwork
{
    public:
        NwConnection listener;
        YmsgHead head;
        
        bool pmToChat,stripYmsgFormats,nickRefresh;
        bool sendClientMsg(string src,const string& dst,const string& txt,bool chat=false);
        bool sendClientUserlist(bool appendlist);
        bool respClientMode(const string& src,const string& name, bool& mode, bool hasvalue, bool value);
        bool respClientQuery(const string& src,const string& query);
        
        bool sendMsg(const YmsgPacket& packet);
        bool sendMsg(int typ, const YmsgField& f, int sta=1);
        bool sendMsg(const tYmsgHead& tHeadRef, const YmsgField& f);//deprecate this
        //bool sendMsg(const tYmsgHead& tHeadRef, vector<const YmsgField> fields);
        //bool sendMsg(const tYmsgHead& tHeadRef, const YmsgItem& item);
        //bool sendMsg(const YmsgPacket&);
        
        
        bool checkErrors(int nBytes);
        
		void stepIncoming(const YmsgPacket& packet);
        void stepIncoming(const string& fields);//assumes 'head' set to incoming header by stepRecv (necessary for stepRecv processing).
        void stepActions();
        void stepRecv();
        void step(NwStepState state=NW_STEP);
        void notifyStateText(const string& state);
        
        
        void init(int mode=0);
        void init(unsigned short ver,unsigned short vid,unsigned int sid);
        YMSG(unsigned short ver,unsigned short vid,unsigned int sid);
        YMSG::YMSG();
        ~YMSG();
        void debug();
        void translate();
        string getdata(const string& data,int num);
        bool setuser(const YmsgField& f);
        bool setuser(const string& data,int num);
		bool setuser(const YmsgItem& content,int num,int occur=1);

        YmsgField GetField(const string& data,int num=-1,int occur=1);
        //string StripText(const string& s);
};



